using System.Collections.Generic;

namespace OracleInternal.SqlAndPlsqlParser
{
	internal class StringTokenizer
	{
		private List<LexerToken> m_vTokens;

		private int m_vCurIdx = -1;

		private int m_vTokensCount = -1;

		public StringTokenizer(string src, DoubleStageCharPropertiesTable charTable, bool includeDelims)
		{
			if (src == null || charTable == null)
			{
				throw new ParserException(ParserExceptionType.StringTokenizer, ParserExceptionError.NullTokenOrPattern, OracleScParserErrorStrings.GetErrorString(ParserExceptionError.NullTokenOrPattern));
			}
			Tokenize(src, charTable, includeDelims);
			m_vCurIdx = ((m_vTokensCount <= 0) ? (-1) : 0);
		}

		private void Tokenize(string src, DoubleStageCharPropertiesTable charTable, bool includeDelims)
		{
			int num = 0;
			int num2 = 0;
			int length = src.Length;
			m_vTokens = new List<LexerToken>();
			while (num < length)
			{
				if (num2 == length)
				{
					m_vTokens.Add(new LexerToken(src, num, num2));
					break;
				}
				char c = src[num2];
				if (charTable.Contains(c))
				{
					if (num != num2)
					{
						m_vTokens.Add(new LexerToken(src, num, num2));
					}
					if (includeDelims)
					{
						m_vTokens.Add(new LexerToken(src, num2, num2 + 1));
					}
					num = ++num2;
				}
				else
				{
					num2++;
				}
			}
			m_vTokensCount = m_vTokens.Count;
		}

		public bool HasMoreTokens()
		{
			return m_vCurIdx < m_vTokensCount;
		}

		public LexerToken NextToken()
		{
			return m_vTokens[m_vCurIdx++];
		}

		public LexerToken PeekNextToken()
		{
			if (m_vCurIdx < m_vTokensCount)
			{
				return m_vTokens[m_vCurIdx];
			}
			return null;
		}
	}
}
